<template>
	<basic-container>
		<avue-crud :option="option" :data="data" :page="page" ref="crud" @search-change="searchChange" @search-reset="searchReset"
		 @current-change="currentChange" @size-change="sizeChange" @on-load="onLoad">
			<template slot="menuRight">
				<el-radio-group @change="searchReset" v-model="status" size="mini" style="margin-right: 50px;">
					<el-radio-button label="">所有</el-radio-button>
					<el-radio-button :label="item.value" v-for="(item,i) in statusItem" :key="i">{{item.label}}</el-radio-button>
				</el-radio-group>
			</template>
			<template slot-scope="{row}" slot="isUp">
				<el-tag v-for="(item,i) in statusItem" size="mini" :key="i" :type="item.type" v-if="item.value == row.isUp">{{item.label}}</el-tag>
			</template>
		</avue-crud>
	</basic-container>
</template>

<script>
	import request from '@/router/axios';

	export default {
		props: {
			pid: "",
			bar: "",
			search: true,
			isUp: true
		},
		data() {
			return {
				statusItem: [{
					value: 1,
					type: '',
					label: '上架'
				}, {
					value: 0,
					type: 'info',
					label: '下架'
				}],
				status: "",
				query: {},
				page: {
					pageSize: 10,
					currentPage: 1,
					total: 0
				},
				option: {
					searchMenuSpan: 6,
					border: true,
					index: true,
					menu: false,
					addBtn: false,
					searchShow: true,
					refreshBtn: false,
					excelBtn: true,
					showSummary: true,
					sumColumnList: [{
						name: 'quantity',
						type: 'sum'
					}],
					column: [{
							label: "相关单号",
							search: true,
							prop: "mainCode"
						}, {
							label: "仓库",
							search: true,
							prop: "storeCode"
						}, {
							label: "库位",
							prop: "localCode",
							width: 100
						},
						{
							label: "条码",
							search: true,
							prop: "barCode"
						},
						{
							label: "上架数量",
							prop: "quantity",
							width: 100
						},
						{
							label: '类型',
							prop: 'isUp',
							width: '60px',
							slot: true
						},
						{
							label: "操作时间",
							prop: "updatedOn",
							width: 160
						},
						{
							label: "操作人",
							prop: "createdBy",
							width: 100
						}
					]
				},
				data: []
			};
		},
		created() {
			this.query.mainCode = this.pid;
			this.query.barCode = this.bar;
			this.option.searchShow = this.search;
		},
		methods: {
			searchReset() {
				this.query = {};
				this.page.currentPage = 1;
				this.onLoad(this.page);
			},
			searchChange(params, done) {
				this.page.currentPage = 1;
				this.query = params;
				this.onLoad(this.page);
				done();
			},
			currentChange(currentPage) {
				this.page.currentPage = currentPage;
			},
			sizeChange(pageSize) {
				this.page.pageSize = pageSize;
			},
			onLoad(page) {
				request({
					url: '2/api/WmsLog/getpages',
					params: {
						key: this.query.barCode == undefined ? '' : this.query.barCode,
						type: this.query.mainCode == undefined ? '' : this.query.mainCode,
						status: this.status == undefined ? '' : this.status,
						where: this.query.storeCode == undefined ? '' : this.query.storeCode,
						page: page.currentPage,
						limit: page.pageSize
					}
				}).then(res => {
					const data = res.data
					this.data = data.data;
					this.page.total = data.remark;
				});
			}
		},
		computed: {},
		watch: {}
	};
</script>

<style>
</style>
